package io.wins.vertx.entity;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.wins.vertx.utils.UUIDUtils;
import org.apache.commons.lang3.StringUtils;

@DataObject(generateConverter = true)
public class User {
    public final String id;
    public String loginId;
    public String password;
    public String salt;
    public long userType;
    public long lastLogin;

    public User(final JsonObject json) {
        UserConverter.fromJson(json, this);
        this.id = StringUtils.isEmpty(json.getString("id")) ?
            UUIDUtils.genId() : json.getString("id");
    }

    public JsonObject toJson() {
        final JsonObject json = new JsonObject();
        UserConverter.toJson(this, json);
        return json;
    }

    public JsonObject toSimpleUser() {
        final JsonObject json = new JsonObject();
        json.put("userId", this.id);
        json.put("loginId", this.loginId);
        json.put("userType", this.userType);
        json.put("lastLogin", this.lastLogin);
        return json;
    }

    public String getId() {
        return this.id;
    }

    public String getLoginId() {
        return this.loginId;
    }

    public void setLoginId(final String loginId) {
        this.loginId = loginId;
    }

    public String getSalt() {
        return this.salt;
    }

    public void setSalt(final String salt) {
        this.salt = salt;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(final String password) {
        this.password = password;
    }

    public long getLastLogin() {
        return this.lastLogin;
    }

    public void setLastLogin(final long lastLogin) {
        this.lastLogin = lastLogin;
    }

    public long getUserType() {
        return this.userType;
    }

    public void setUserType(final long userType) {
        this.userType = userType;
    }
}